import { InMemoryDbService } from 'angular-in-memory-web-api';
import { Hero } from './hero';
import { Injectable } from '@angular/core';

@Injectable({
  providedIn: 'root'
})
export class InMemoryDataService implements InMemoryDbService {

  createDb() {
    const heroes = [
      { id: 1, name: 'Hello world' },
      { id: 2, name: 'Test' },
      { id: 3, name: 'Javascript' },
      { id: 4, name: 'NodeJS' },
      { id: 5, name: 'Angular7' },
      { id: 6, name: 'Ionic4' },
      { id: 7, name: 'Codorva' }
    ];
    return { heroes };
  }

  genId(heroes: Hero[]): number {
    return heroes.length > 0 ? Math.max(...heroes.map(hero => hero.id)) + 1 : 1;
  }

  constructor() { }
}
